package com.cskaoyan.controller;

import com.cskaoyan.bean.Topic;
import com.cskaoyan.service.TopicService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.TopicVo;
import net.sf.jsqlparser.statement.select.Top;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TopicController {
    @Autowired
    TopicService topicService;

    /**
     * by:whl
     * 功能：list【get】
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @RequestMapping("admin/topic/list")//page=1&limit=20&sort=add_time&order=desc
    public BaseRespVo list(Integer page,Integer limit,String sort,String order){
        TopicVo topicVo = topicService.topicList(page,limit,sort,order);
        return BaseRespVo.ok(topicVo);
    }

    /**
     * by:whl
     * 功能：create【post】
     * @return
     */
    @RequestMapping("admin/topic/create")
    public BaseRespVo create(@RequestBody Topic topic){
        Topic data = topicService.topicCreate(topic);
        return BaseRespVo.ok(data);
    }

    /**
     * by:whl
     * 功能：update【post】
     * @return
     */
    @RequestMapping("admin/topic/update")//page=1&limit=20&sort=add_time&order=desc
    public BaseRespVo update(@RequestBody Topic topic){
        Topic data = topicService.topicUpdate(topic);
        return BaseRespVo.ok(data);
    }

    /**
     * by:whl
     * 功能：delete【post】
     * @return
     */
    @RequestMapping("admin/topic/delete")//page=1&limit=20&sort=add_time&order=desc
    public BaseRespVo delete(@RequestBody Topic topic){
        topicService.topicDelete(topic);
        return BaseRespVo.ok();
    }

}
